package net.zretc.entity;

import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.IdType;
import java.util.Date;

/**
 * 用户实体类
 * 用于存储用户和管理员信息
 */
@TableName("users") // 指定数据库表名为users
public class User {

    // 用户ID，主键，自增
    @TableId(type = IdType.AUTO)
    private Integer userId;

    // 用户名
    private String username;

    // 密码
    private String password;

    // 创建时间
    private Date createTime;

    // 是否为管理员（0=普通用户，1=管理员）
    @TableField("is_admin") // 映射数据库字段is_admin
    private boolean isAdmin;

    // 无参构造函数
    public User() {
    }

    // 有参构造函数
    public User(String username, String password) {
        this.username = username;
        this.password = password;
        this.createTime = new Date();
        this.isAdmin = false; // 默认为普通用户
    }

    // Getter 和 Setter 方法
    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    // 获取是否为管理员
    public boolean isAdmin() {
        return isAdmin;
    }

    // 设置是否为管理员
    public void setAdmin(boolean admin) {
        isAdmin = admin;
    }

    @Override
    public String toString() {
        return "User{" +
                "userId=" + userId +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", createTime=" + createTime +
                ", isAdmin=" + isAdmin +
                '}';
    }
}